package cn.nr19.jian.`object`

import cn.nr19.jian.token.J2Node
import cn.nr19.jian.token.NFunNode

/**
 * 不同于 jianlei2，这个本身就属于一个类，
 */
open class JianLeiChild(val parent: JianLeiApi) : JianLei() {

    override fun getBaseUrl(url: String): String {
        return parent.getBaseUrl(url)
    }


    override fun getFun(name: String, pars: List<Any>): NFunNode? {
        return super.getFun(name, pars)?:parent?.getFun(name,pars)
    }

    override fun getVar(key: String): Any? {
        return super.getVar(key)?:parent?.getVar(key)
    }

    override fun getEvent(name: String, parsSize: Int): J2Node? {
        return super.getEvent(name, parsSize) ?: parent.getEvent(name, parsSize)
    }
    override fun getFileAbsPath(path: String): String {
        return parent.getFileAbsPath(path)
    }

    override fun getConf(key: String): Any? {
        return super.getConf(key) ?: parent.getConf(key)
    }
    override fun setVar(name: String, value: Any) {
        try {
            super.setVar(name, value)
        }catch (e : Exception){
             parent.setVar(name,value)
        }
    }

    override fun vars(): Map<String, Any> {
        return HashMap<String,Any>().apply {
            putAll(parent.vars())
            putAll(vars)
        }
    }

    override fun funs(): List<NFunNode> {
        return ArrayList<NFunNode>().apply {
            addAll(parent.funs())
            addAll(funs)
        }

    }

    override fun events(): Map<String, J2Node> {
        return HashMap<String, J2Node>().apply {
            putAll(parent.events())
            putAll(listener)
        }
    }

}